package com.hspedu.Object;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/1/23
 * @time 18:35
 */
public class EqualsExercise01 {
    public static void main(String[] args) {
        Person person1 = new Person("jack", 10, '男');
        Person person2 = new Person("jack", 10, '男');
        System.out.println(person1.equals(person2));
    }
}

class Person{
    private String name;
    private int age;
    private char gender;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public Person(String name, int age, char gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }
    @Override
    public boolean equals(Object obj){
        if ( this == obj ){
            return true;
        }

        if (obj instanceof Person){
            Person newObj = (Person) obj;
            if (newObj.name.equals(this.name)
                    && newObj.age == this.age
                    && newObj.gender == this.gender){
                return true;
            }
        }
        return false;
    }

}
